import Vue from 'vue'
import App from './App'

//引入vuex 并且把vuex注册为Vue的插件
import Vuex from "vuex";
Vue.use(Vuex)
//创建仓库 并 注册
const store = new Vuex.Store({
    strict: true,
    //数据
    state:{
      firstName:"姆",
      lastName:"达",
      count:0
    },
    //仓库内部的计算属性
    getters:{
      fullName(state){
        return `${state.lastName}-${state.firstName}`
      },
      //判断当前的count是奇是偶
      flag(state){
        return state.count%2===0 ? "偶":"奇"
      }
    },
    mutations:{
      add(state){
        state.count++
      },
      des(state){
        state.count--
      }
    },
    actions:{
      add(store,{msg}){
        console.log(msg);
        store.commit("add")
      },
      des(store){
        store.commit("des")
      }
    }
})

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App },
  template: '<App/>',
  store //注册仓库
})
